package com.flight.trans.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.flight.trans.R;
import com.flight.trans.base.BaseRecyclerAdapter;
import com.flight.trans.base.BaseViewHolder;
import com.flight.trans.bean.EnterPortStorageBean;

import java.util.List;

/**
 * 存放区域容器
 */
public class StorageAreaContainerAdapter extends BaseRecyclerAdapter<EnterPortStorageBean> {

    public StorageAreaContainerAdapter(Context mContext, List<EnterPortStorageBean> mList , boolean isEditor) {
        super(mContext, mList);
        this.IsEditor = isEditor ;
    }

    @Override
    public int setContentView() {
        return R.layout.adapter_storage_area_container;
    }

    @Override
    protected void bindData(BaseViewHolder holder, EnterPortStorageBean data, int position) {
        Button mBtnAddContent = holder.findViewById(R.id.mBtnAddContent);
        LinearLayout mLlInputContent = holder.findViewById(R.id.mLlInputContent);

        TextView mTvContainer = holder.findViewById(R.id.mTvContainer);
        TextView mTvStorageArea = holder.findViewById(R.id.mTvStorageArea);

        if(data == null){
            mBtnAddContent.setVisibility(View.VISIBLE);
            mLlInputContent.setVisibility(View.GONE);

            if(IsEditor)
                setOnItemClickListener(mBtnAddContent , position);
        } else {
            mBtnAddContent.setVisibility(View.GONE);
            mLlInputContent.setVisibility(View.VISIBLE);

            mTvContainer.setText(data.getTransportCode());
            mTvStorageArea.setText(TextUtils.isEmpty(data.getWarehouseAreaName()) ? "" : data.getWarehouseAreaName());

            if(IsEditor) {
                // 条目点击事件
                setOnItemLongClickListener(mLlInputContent, position);
                // 新增条目
                setOnTextClickListener(mBtnAddContent , position);
                // 字段点击
                setOnTextClickListener(mTvContainer , position);
                setOnTextClickListener(mTvStorageArea , position);
            }
        }
    }
}
